package com.hengfoxwolf.commonbase.base
import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.ViewDataBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope

abstract class BaseActivity2<T : ViewDataBinding>(block: (LayoutInflater) -> T) : AppCompatActivity(), CoroutineScope by MainScope() {

    private val mBlock = block

    protected lateinit var mBinding : T

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        preInit()
        mBinding = mBlock.invoke(layoutInflater)
        setContentView(mBinding.root)
        init(savedInstanceState)
    }


    override fun onDestroy() {
        super.onDestroy()
        mBinding.unbind()
    }

    open fun preInit() {}

    abstract fun init(savedInstanceState: Bundle?)
}